from flask import Flask, request, make_response, redirect, abort, render_template
from flask_script import Manager
from werkzeug.security import generate_password_hash, check_password_hash
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate, MigrateCommand
from flask_login import LoginManager
from flask_jwt_extended import JWTManager

# 创建数据库连接
db = SQLAlchemy()
jwt = JWTManager()

# 使用工厂方法创建app，方便测试
def create_app(config=None):
    app = Flask(__name__)
    if config is not None:
        # 加载配置信息
        app.config.from_object(config)

    #注册蓝图对象
    from application.common.error_handler import error
    from application.api.users.views import api_users





    app.register_blueprint(api_users, url_prefix='/api/users')

    app.register_blueprint(error, url_prefix='/error')


    # 跟app发生关系
    db.init_app(app)
    jwt.init_app(app)

    return app






